#include <Richedit.h>
#include "RichEdit.hpp"
#include "ContainerControl.hpp"
#include <map>
#include "Application.hpp"
#include "WindowForm.hpp"
using namespace NAMESPACENAME;
HMODULE RichEdit::hRichEdit;
extern std::map<HWND, Control*> __mapWindows;
RichEdit::RichEdit(const Rectangle& rect, String title, ContainerControl* parent) :
	Control(parent)
{
	if (!hRichEdit)
		if (!(hRichEdit = LoadLibraryW(L"Msftedit.dll")))
			throw std::exception("Load Rich Edit Control Failed!", 0);
	auto p(title.UnsafeGetString());
	hWnd = CreateWindowExW(
		ES_EX_NOCALLOLEINIT,
		MSFTEDIT_CLASS,
		p,
		WS_CHILD | ES_SAVESEL | ES_SELFIME | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN,
		rect.x,
		rect.y,
		rect.width,
		rect.height,
		parent->WindowHandle(),
		GetId(parent),
		Application::GetInstance(),
		nullptr
	);
	delete[] p;
	if (hWnd)
		__mapWindows.emplace(std::make_pair(hWnd, this));
	else
		throw std::exception("Create Button Failed!", 0);
}
void RichEdit::OnDestroy()
{
}
void RichEdit::OnClose()
{
}
void RichEdit::OnNcPaint(HRGN hRgn)
{
}
void RichEdit::OnCommand(UINT message, UINT id, Control* control)
{
}
void RichEdit::OnLoad()
{
	::SetWindowLongPtrW(hWnd, GWL_STYLE, ::GetWindowLongPtrW(hWnd, GWL_STYLE) | WS_VISIBLE);
}
void RichEdit::OnUnLoad()
{
	::SetWindowLongPtrW(hWnd, GWL_STYLE, ::GetWindowLongPtrW(hWnd, GWL_STYLE) & ~WS_VISIBLE);
}
void RichEdit::OnPaint()
{
}